//
//  ViewController.m
//  轮波器1
//
//  Created by mac on 01-1-1.
//  Copyright (c) 2001年 hyd. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *imageId;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

//上一张按钮点击事件
- (IBAction)upImage;
//下一张按钮点击事件

- (IBAction)nextImage;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)upImage {
    
    NSString * myImageId = self.imageId.text;
    NSString * imageName = [[NSString alloc]init];
    NSString * idOfstr= [myImageId substringToIndex:2];
   // NSLog(@"%@",idOfstr);
    int idOfInt = [idOfstr intValue];
    //如果是第一张就提示不能往前翻
    if (idOfInt == 1) {
        UIAlertView * msg = [[UIAlertView alloc]initWithTitle:@"提示 " message:@"已经是第一张,前面没有了" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
        [msg show];
    }//不是第一张往前翻
    else{
        idOfInt--;
        if (idOfInt<10) {
            idOfstr = [NSString stringWithFormat:@"0%d/24",idOfInt];
        }else
        {
            idOfstr = [NSString stringWithFormat:@"%d/24",idOfInt];
        }
        imageName = [NSString stringWithFormat:@"%d.jpg",idOfInt];
        //将文字和图片显示出来
        self.imageId.text = idOfstr;
        self.imageView.image = [UIImage imageNamed:imageName];
    }
}

- (IBAction)nextImage {
    
    NSString * myImageId = self.imageId.text;
    NSString * imageName = [[NSString alloc]init];
    NSString * idOfstr= [myImageId substringToIndex:2];
    //NSLog(@"%@",idOfstr);
    int idOfInt = [idOfstr intValue];
    //如果是第一张就提示不能往前翻
    if (idOfInt == 24) {
        UIAlertView * msg = [[UIAlertView alloc]initWithTitle:@"提示 " message:@"已经是最后一张,后面没有了" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
        [msg show];
    }//不是第一张往前翻
    else{
        idOfInt++;
        if (idOfInt<10) {
            idOfstr = [NSString stringWithFormat:@"0%d/24",idOfInt];
        }else
        {
            idOfstr = [NSString stringWithFormat:@"%d/24",idOfInt];
        }
        imageName = [NSString stringWithFormat:@"%d.jpg",idOfInt];
        //将文字和图片显示出来
        self.imageId.text = idOfstr;
        self.imageView.image = [UIImage imageNamed:imageName];
    }
    
    
    
}
@end
